package cn.rocky.prepare;

public class searchInsert {

    public int searchInsert(int[] nums, int target) {
        return binarySearch(nums,target);
    }

    public int binarySearch(int[] nums, int target) {
        int left = 0, right = nums.length - 1, ans = nums.length;
        while (left <= right) {
            int mid = ((right - left) >> 1) + left;
            if (nums[mid] >= target) {
                right = mid - 1;
                ans = mid;
            } else {
                left = mid + 1;
            }
        }
        return ans;
    }
}